home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gxshade.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  7.7 KB  |  211 lines

  1. /* Copyright (C) 1998, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gxshade.h,v 1.3 2000/09/19 19:00:40 lpd Exp $ */
  20. /* Internal definitions for shading rendering */
  21.  
  22. #ifndef gxshade_INCLUDED
  23. #  define gxshade_INCLUDED
  24.  
  25. #include "gsshade.h"
  26. #include "gxfixed.h"        /* for gxmatrix.h */
  27. #include "gxmatrix.h"        /* for gs_matrix_fixed */
  28. #include "stream.h"
  29.  
  30. /*
  31.    All shadings are defined with respect to some parameter that varies
  32.    continuously over some range; the shading defines a mapping from the
  33.    parameter values to colors and user space coordinates.  Here are the
  34.    mappings for the 7 currently defined shading types:
  35.  
  36.    Type Param space     Param => color          Param => User space
  37.    ---- -----------     --------------          -------------------
  38.    1    2-D Domain      Function                Matrix
  39.    2    1-D Domain      Function + Extend       perp. to Coords
  40.    3    1-D Domain      Function + Extend       circles per Coords
  41.    4,5  triangle x      Gouraud interp. on      Gouraud interp. on
  42.     2-D in tri.    Decode => corner        triangle corners
  43.             values => Function
  44.    6    patch x (u,v)   Decode => bilinear      Sc + Sd - Sb on each patch
  45.     in patch    interp. on corner
  46.             values => Function
  47.    7    see 6           see 6                   Sum(i) Sum(j) Pij*Bi(u)*Bj(v)
  48.  
  49.    To be able to render a portion of a shading usefully, we must be able to
  50.    do two things:
  51.  
  52.    - Determine what range of parameter values is sufficient to cover
  53.    the region being filled;
  54.  
  55.    - Evaluate the color at enough points to fill the region (in
  56.    device space).
  57.  
  58.    Note that the latter may be implemented by a mix of evaluation and
  59.    interpolation, especially for types 3, 6, and 7 where an exact mapping
  60.    may be prohibitively expensive.
  61.  
  62.    Except for type 3, where circles turn into ellipses, the CTM can get
  63.    folded into the parameter => user space mapping, since in all other
  64.    cases, the mapping space is closed under linear transformations of
  65.    the output.
  66.  */
  67.  
  68. /* Define types and rendering procedures for the individual shadings. */
  69. typedef struct gs_shading_Fb_s {
  70.     gs_shading_head_t head;
  71.     gs_shading_Fb_params_t params;
  72. } gs_shading_Fb_t;
  73. SHADING_FILL_RECTANGLE_PROC(gs_shading_Fb_fill_rectangle);
  74.  
  75. typedef struct gs_shading_A_s {
  76.     gs_shading_head_t head;
  77.     gs_shading_A_params_t params;
  78. } gs_shading_A_t;
  79. SHADING_FILL_RECTANGLE_PROC(gs_shading_A_fill_rectangle);
  80.  
  81. typedef struct gs_shading_R_s {
  82.     gs_shading_head_t head;
  83.     gs_shading_R_params_t params;
  84. } gs_shading_R_t;
  85. SHADING_FILL_RECTANGLE_PROC(gs_shading_R_fill_rectangle);
  86.  
  87. typedef struct gs_shading_FfGt_s {
  88.     gs_shading_head_t head;
  89.     gs_shading_FfGt_params_t params;
  90. } gs_shading_FfGt_t;
  91. SHADING_FILL_RECTANGLE_PROC(gs_shading_FfGt_fill_rectangle);
  92.  
  93. typedef struct gs_shading_LfGt_s {
  94.     gs_shading_head_t head;
  95.     gs_shading_LfGt_params_t params;
  96. } gs_shading_LfGt_t;
  97. SHADING_FILL_RECTANGLE_PROC(gs_shading_LfGt_fill_rectangle);
  98.  
  99. typedef struct gs_shading_Cp_s {
  100.     gs_shading_head_t head;
  101.     gs_shading_Cp_params_t params;
  102. } gs_shading_Cp_t;
  103. SHADING_FILL_RECTANGLE_PROC(gs_shading_Cp_fill_rectangle);
  104.  
  105. typedef struct gs_shading_Tpp_s {
  106.     gs_shading_head_t head;
  107.     gs_shading_Tpp_params_t params;
  108. } gs_shading_Tpp_t;
  109. SHADING_FILL_RECTANGLE_PROC(gs_shading_Tpp_fill_rectangle);
  110.  
  111. /* Define a stream for decoding packed coordinate values. */
  112. typedef struct shade_coord_stream_s shade_coord_stream_t;
  113. struct shade_coord_stream_s {
  114.     stream ds;            /* stream if DataSource isn't one already -- */
  115.                 /* first for GC-ability (maybe unneeded?) */
  116.     stream *s;            /* DataSource or &ds */
  117.     uint bits;            /* shifted bits of current byte */
  118.     int left;            /* # of bits left in bits */
  119.     const gs_shading_mesh_params_t *params;
  120.     const gs_matrix_fixed *pctm;
  121.     int (*get_value)(P3(shade_coord_stream_t *cs, int num_bits, uint *pvalue));
  122.     int (*get_decoded)(P4(shade_coord_stream_t *cs, int num_bits,
  123.               const float decode[2], float *pvalue));
  124. };
  125.  
  126. /* Define one vertex of a mesh. */
  127. typedef struct mesh_vertex_s {
  128.     gs_fixed_point p;
  129.     float cc[GS_CLIENT_COLOR_MAX_COMPONENTS];
  130. } mesh_vertex_t;
  131.  
  132. /* Initialize a packed value stream. */
  133. void shade_next_init(P3(shade_coord_stream_t * cs,
  134.             const gs_shading_mesh_params_t * params,
  135.             const gs_imager_state * pis));
  136.  
  137. /* Get the next flag value. */
  138. int shade_next_flag(P2(shade_coord_stream_t * cs, int BitsPerFlag));
  139.  
  140. /* Get one or more coordinate pairs. */
  141. int shade_next_coords(P3(shade_coord_stream_t * cs, gs_fixed_point * ppt,
  142.              int num_points));
  143.  
  144. /* Get a color.  Currently all this does is look up Indexed colors. */
  145. int shade_next_color(P2(shade_coord_stream_t * cs, float *pc));
  146.  
  147. /* Get the next vertex for a mesh element. */
  148. int shade_next_vertex(P2(shade_coord_stream_t * cs, mesh_vertex_t * vertex));
  149.  
  150. /*
  151.    Currently, all shading fill procedures follow the same algorithm:
  152.  
  153.    - Conservatively inverse-transform the rectangle being filled to a linear
  154.    or rectangular range of values in the parameter space.
  155.  
  156.    - Compute the color values at the extrema of the range.
  157.  
  158.    - If possible, compute the parameter range corresponding to a single
  159.    device pixel.
  160.  
  161.    - Recursively do the following, passing the parameter range and extremal
  162.    color values as the recursion arguments:
  163.  
  164.    - If the color values are equal to within the tolerance given by the
  165.    smoothness in the graphics state, or if the range of parameters maps
  166.    to a single device pixel, fill the range with the (0) or (0,0) color.
  167.  
  168.    - Otherwise, subdivide and recurse.  If the parameter range is 2-D,
  169.    subdivide the axis with the largest color difference.
  170.  
  171.    For shadings based on a function, if the function is not monotonic, the
  172.    smoothness test must only be applied when the parameter range extrema are
  173.    all interpolated from the same entries in the Function.  (We don't
  174.    currently do this.)
  175.  
  176.  */
  177.  
  178. /* Define the common structure for recursive subdivision. */
  179. #define shading_fill_state_common\
  180.   gx_device *dev;\
  181.   gs_imager_state *pis;\
  182.   int num_components;        /* # of color components */\
  183.   float cc_max_error[GS_CLIENT_COLOR_MAX_COMPONENTS]
  184. typedef struct shading_fill_state_s {
  185.     shading_fill_state_common;
  186. } shading_fill_state_t;
  187.  
  188. /* Initialize the common parts of the recursion state. */
  189. void shade_init_fill_state(P4(shading_fill_state_t * pfs,
  190.                   const gs_shading_t * psh, gx_device * dev,
  191.                   gs_imager_state * pis));
  192.  
  193. /* Transform a bounding box into device space. */
  194. int shade_bbox_transform2fixed(P3(const gs_rect * rect,
  195.                   const gs_imager_state * pis,
  196.                   gs_fixed_rect * rfixed));
  197.  
  198. /* Check whether 4 colors fall within the smoothness criterion. */
  199. bool shade_colors4_converge(P2(const gs_client_color cc[4],
  200.                    const shading_fill_state_t * pfs));
  201.  
  202. /* Fill one piece of a shading. */
  203. #ifndef gx_device_color_DEFINED
  204. #  define gx_device_color_DEFINED
  205. typedef struct gx_device_color_s gx_device_color;
  206. #endif
  207. int shade_fill_path(P3(const shading_fill_state_t * pfs, gx_path * ppath,
  208.                gx_device_color * pdevc));
  209.  
  210. #endif /* gxshade_INCLUDED */
  211.